package com.SouthernWall_404.AgeSuitcase.Common.world.item;

import com.SouthernWall_404.AgeSuitcase.Client.Gui.Screens.ConstractScreen;
import com.SouthernWall_404.AgeSuitcase.Common.API.GeneralAPI;
import com.SouthernWall_404.AgeSuitcase.Common.API.Info.ConstractInfo;
import com.SouthernWall_404.AgeSuitcase.Common.AgeSuitcase;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ConstractItem extends FileItem {

    public static String CONSTRACT_TAG="constract";

    public ConstractItem(Properties p_41383_) {
        super(p_41383_);
    }


    public static void setConstract(ItemStack itemStack,ConstractInfo constract)
    {
        CompoundTag constractPack=constract.getConstractPack();

        CompoundTag modPack= getOrCreateModPack(itemStack);
        modPack.put(CONSTRACT_TAG,constractPack);//存入modPack

        CompoundTag nbt=itemStack.getOrCreateTag();
        nbt.put(AgeSuitcase.MODID,modPack);
    }

    public static ConstractInfo getConstract(ItemStack itemStack)
    {
        ConstractInfo constractInfo=new ConstractInfo(itemStack);

        return constractInfo;
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {

        if(level.isClientSide)
        {
            Minecraft.getInstance().setScreen(new ConstractScreen(Component.empty()));
        }

        return super.use(level, player, hand);
    }

    @Override
    public void appendHoverText(ItemStack itemStack, @Nullable Level p_41422_, List<Component> tooltips, TooltipFlag p_41424_) {
        super.appendHoverText(itemStack, p_41422_, tooltips, p_41424_);
        ConstractInfo constractInfo=getConstract(itemStack);
        List<String> A=constractInfo.A;
        List<String> B=constractInfo.B;

        String AString= GeneralAPI.getLongStringFromList(A);
        String BString=GeneralAPI.getLongStringFromList(B);

        if(AString!=null&&BString!=null)
        {
            tooltips.add(Component.translatable("A:"+AString));
            tooltips.add(Component.translatable("B:"+BString));
        }


    }


}
